FUNCTION YBC_SWS_CALLBACK_PO.
*"----------------------------------------------------------------------
*"*"本地接口：
*"  IMPORTING
*"     VALUE(IV_APPLEVEL) TYPE  YBC_SWS_APPROVER-APPLEVEL
*"     VALUE(IV_BUSINESSID) TYPE  YBC_SWS_REQUEST-BUSINESSID
*"     VALUE(IV_ACTION) TYPE  YBC_SWS_APPROVER-ACTION
*"     VALUE(IV_COMMENTS) TYPE  YBC_SWS_APPROVER-COMMENTS OPTIONAL
*"  EXPORTING
*"     VALUE(ES_MSG) TYPE  BAPIRET2
*"     VALUE(EV_FINISHED) TYPE  CHAR1
*"  TABLES
*"      ET_APPROVER_NEXT STRUCTURE  YBCS_SWS_APPROVER OPTIONAL
*"----------------------------------------------------------------------
**********************************************************************
* 若审批人由SwiftSAP配置实现，请勿修改ET_APPROVER_NEXT及EV_FINISHED 内容
* 若审批人由外部函数提供：若是最后一级审批，需设置EV_FINISHED = 'X'
*                        若不是最后一级审批，需提供ET_APPROVER_NEXT
**********************************************************************

  DATA:
    LV_STR      TYPE STRING,
    LV_EBELN    TYPE EKKO-EBELN,
    LV_REL_CODE TYPE BAPIMMPARA-PO_REL_COD,
    LV_RET_CODE TYPE SY-SUBRC,
    LT_RETURN   TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
    LT_WF_01    TYPE TABLE OF YBC_SWS_WF_01 WITH HEADER LINE.

  CLEAR:
    ES_MSG.

  LV_EBELN = IV_BUSINESSID.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      INPUT  = LV_EBELN
    IMPORTING
      OUTPUT = LV_EBELN.

  CASE IV_ACTION.
    WHEN 'REJECT'.
      CALL FUNCTION 'YBC_SWS_PO_REJECT'
        EXPORTING
          IV_EBELN  = LV_EBELN
        TABLES
          ET_RETURN = LT_RETURN.

      LOOP AT LT_RETURN WHERE TYPE = 'E'.
        ES_MSG-TYPE = 'E'.

        CLEAR LV_STR.
        MESSAGE ID LT_RETURN-ID TYPE LT_RETURN-TYPE NUMBER LT_RETURN-NUMBER
               INTO LV_STR
               WITH LT_RETURN-MESSAGE_V1 LT_RETURN-MESSAGE_V2 LT_RETURN-MESSAGE_V3 LT_RETURN-MESSAGE_V4.
        CONCATENATE ES_MSG-MESSAGE LV_STR INTO ES_MSG-MESSAGE SEPARATED BY SPACE.
      ENDLOOP.

    WHEN 'APPROVE'.
      CONDENSE IV_APPLEVEL.
      LV_REL_CODE = IV_APPLEVEL.
      CALL FUNCTION 'BAPI_PO_RELEASE'
        EXPORTING
          PURCHASEORDER          = LV_EBELN
          PO_REL_CODE            = LV_REL_CODE
*         USE_EXCEPTIONS         = 'X'
*         NO_COMMIT              = ' '
        IMPORTING
*         REL_STATUS_NEW         =
*         REL_INDICATOR_NEW      =
          RET_CODE               = LV_RET_CODE
*       TABLES
*         RETURN                 = lt_return
        EXCEPTIONS
          AUTHORITY_CHECK_FAIL   = 1
          DOCUMENT_NOT_FOUND     = 2
          ENQUEUE_FAIL           = 3
          PREREQUISITE_FAIL      = 4
          RELEASE_ALREADY_POSTED = 5
          RESPONSIBILITY_FAIL    = 6
          OTHERS                 = 7.
      IF SY-SUBRC <> 0.
        ES_MSG-TYPE = 'E'.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 INTO ES_MSG-MESSAGE
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        RETURN.
      ENDIF.
    WHEN OTHERS.
  ENDCASE.
ENDFUNCTION.
